﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace ZingMe
{
    public partial class Form1 : Form
    {
        public string ID = "";
        public string Pass = "";

        public Form1()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //Our postvars
            byte[] buffer = Encoding.ASCII.GetBytes("pid=25&u1=http://login.me.zing.vn/login/success&fp=http://login.me.zing.vn/login/fail&u=nguyenhuukaka1&p=HuuNganLam123&longtime=1");
            //Initialization, we use localhost, change if applicable
            HttpWebRequest WebReq =
            (HttpWebRequest)WebRequest.Create("https://sso2.zing.vn/index.php?method=login");
            //Our method is post, otherwise the buffer (postvars) would be useless
            WebReq.Method = "POST";
            //We use form contentType, for the postvars.
            WebReq.ContentType = "application/x-www-form-urlencoded";
            //The length of the buffer (postvars) is used as contentlength.
            WebReq.ContentLength = buffer.Length;
            //We open a stream for writing the postvars
            Stream PostData = WebReq.GetRequestStream();
            //Now we write, and afterwards, we close. Closing is always important!
            PostData.Write(buffer, 0, buffer.Length);
            PostData.Close();
            //Get the response handle, we have no true response yet!
            HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();


            //Now, we read the response (the string), and output it.
            Stream Answer = WebResp.GetResponseStream();
            StreamReader _Answer = new StreamReader(Answer);
            textBox1.Text += _Answer.ReadToEnd();

            foreach (Cookie c in WebResp.Cookies)
            {
                textBox2.Text += c.Name + " : " + c.Value + " \n";
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Initialization
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://login.me.zing.vn/");
            //This time, our method is GET.
            WebReq.Method = "GET";
            //From here on, it's all the same as above.
            HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();       
            

            //Now, we read the response (the string), and output it.
            Stream Answer = WebResp.GetResponseStream();
            StreamReader _Answer = new StreamReader(Answer);
            textBox1.Text += _Answer.ReadToEnd();

            foreach (Cookie c in WebResp.Cookies)
            {
                textBox2.Text += c.Name + " : " + c.Value + " \n";
            }
        }
    }
}
